﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FolderCopier
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void buttonSource_Click(object sender, EventArgs e)
        {
            DialogResult dialogRes =  folderBrowserDialog1.ShowDialog();
            if (dialogRes == DialogResult.OK)
            {

                textBoxSource.Text = folderBrowserDialog1.SelectedPath;

                Environment.SpecialFolder root = folderBrowserDialog1.RootFolder;
            }
        }

        private void buttonDestination_Click(object sender, EventArgs e)
        {
            DialogResult dialogRes = folderBrowserDialog1.ShowDialog();
            if (dialogRes == DialogResult.OK)
            {

                textBoxDestination.Text = folderBrowserDialog1.SelectedPath;

                Environment.SpecialFolder root = folderBrowserDialog1.RootFolder;
            }
        }

        private void buttonCopyStructure_Click(object sender, EventArgs e)
        {
            createFolder(Convert.ToInt16( numericLevel.Value ), textBoxSource.Text.Trim(), textBoxDestination.Text.Trim());

        }

        public static void createFolder(int level,string sourceAddress, string destinationAddress)
        {
            string[] folders = System.IO.Directory.GetDirectories(sourceAddress.Trim());
            for (int i = level; i > 0; --i)
                {                    
                    foreach(string folder in folders)
                    {
                        
                        string folderName = Path.GetFileName(folder);
                        
                        System.IO.Directory.CreateDirectory(destinationAddress + "\\" +  folderName);
                        createFolder(i--, sourceAddress + "\\" + folderName, destinationAddress + "\\" + folderName);
                    }
            }
        }
    }
}
